<template>
  <el-form ref="formRef" :model="form" v-loading="loading">
    <pub-edit-description :ndColumns="2">
      <pub-edit-description-item :span="2" label="注销原因" required>
        <el-form-item prop="cancellationReasonCode" :rules="$formRules.select">
          <pub-select-dict
            v-model="form.cancellationReasonCode"
            dict-code="ZZDA-ZXYY"
            placeholder="请选择"
            width="100%"
          />
        </el-form-item>
      </pub-edit-description-item>
      <pub-edit-description-item :span="2" label="操作人员" required>
        <el-form-item prop="cancellationPerson" :rules="$formRules.input">
          <pub-input v-model="form.cancellationPerson" />
        </el-form-item>
      </pub-edit-description-item>

      <pub-edit-description-item :span="2" label="注销时间" required>
        <el-form-item prop="cancellationTime" :rules="$formRules.select">
          <pub-select-date
            v-model="form.cancellationTime"
            disabled
            type="datetime"
            valueFormat="YYYY-MM-DD HH:mm:ss"
          ></pub-select-date>
        </el-form-item>
      </pub-edit-description-item>
      <pub-edit-description-item
        :span="2"
        label="实际死亡日期"
        required
        v-if="form.cancellationReasonCode == '1'"
      >
        <el-form-item prop="deathTime" :rules="$formRules.select">
          <pub-select-date
            v-model="form.deathTime"
            type="date"
            :disabledDate="disabledDate"
            valueFormat="YYYY-MM-DD"
          ></pub-select-date>
        </el-form-item>
      </pub-edit-description-item>
      <pub-edit-description-item
        :span="2"
        label="注销说明"
        required
        v-if="form.cancellationReasonCode == '2'"
      >
        <el-form-item prop="cancellationExplain" :rules="$formRules.input">
          <pub-textarea v-model="form.cancellationExplain" />
        </el-form-item>
      </pub-edit-description-item>
    </pub-edit-description>
    <div class="dialog-footer-btn">
      <el-button type="default" @click="emit('cancel')">取消</el-button>
      <el-button type="primary" @click="submit" v-prevent-repeat-click>
        保存
      </el-button>
    </div>
  </el-form>
</template>
<script setup>
import { cancel_zzda } from '@/api/basicSetting.js'
import { formatDictCode } from '@/utils/index'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useUserStore } from '@/pinia/modules/user'
import dayjs from 'dayjs'
const emit = defineEmits(['cancel', 'success'])
const props = defineProps({
  status: {
    type: [String, Number],
    default: '1'
  },
  id: {
    type: String,
    default: ''
  },
  // SQ社区服务站管理 JD街道中心管理
  pageName: {
    type: String,
    default: 'SQ'
  }
})
const disabledDate = time => {
  if (form.value.cancellationTime) {
    return time.getTime() > dayjs(form.value.cancellationTime)
  }
}
const form = ref({
  cancellationTime: ''
})
const loading = ref(false)
const moduleOptions = ref([])
const changeStatus = val => {
  // form.value.moduleCode = ''
}

const formRef = ref(null)
const submit = async () => {
  formRef.value.validate(async valid => {
    if (valid) {
      loading.value = true
      form.value.id = props.id
      let res = await cancel_zzda(form.value)
      if (res.succeed) {
        ElMessage({
          type: 'success',
          message: res.msg
        })
        emit('success', 'dialogShow')
      }
      loading.value = false
    }
  })
}

onMounted(() => {
  form.value.cancellationTime = dayjs().format('YYYY-MM-DD hh:mm:ss')
  form.value.cancellationPerson = useUserStore().orgInfo.orgName
})
</script>
    <style lang="scss" scoped></style>
    